#include <iostream>
#include <string>

using namespace std;

int main()
{
    string a;
    int n;
    int count, sum = 0;
    cin >> n;
    while (n--)
    {
        cin >> a;
        auto begin = a.begin() - 1;
        auto end = a.end();
        while (begin != end)
        {
            begin++;
            count = 0;
            while (begin != end && *begin == 'O')
            {
                count++;
                sum += count;
                begin++;
            }
        }
        cout << sum << endl;
    }
    return 0;
}